﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Unimaq.FacturaDBS_Spring.LogicaNegocio.Version2.DBS
{
    public class DBS_Detalle_LineAD_BLL
    {
        public void Convertir(Entidades.Version2.DBS.DBS_Detalle detalle)
        {
            string line = detalle.Linead;

            if (!string.IsNullOrWhiteSpace(line))
            {
                detalle.DetalleLineAD.Ped = !string.IsNullOrWhiteSpace(line.Substring(0, 5)) ? int.Parse(line.Substring(0, 5)) : 0;
                detalle.DetalleLineAD.Ent = !string.IsNullOrWhiteSpace(line.Substring(5, 5)) ? int.Parse(line.Substring(5, 5)) : 0;
                detalle.DetalleLineAD.Pro = line.Substring(10, 4).Trim();
                detalle.DetalleLineAD.NroParte = line.Substring(14, 22).Trim();
                detalle.DetalleLineAD.Descripcion = line.Substring(36, 24).Trim();
                detalle.DetalleLineAD.ValorVenta = !string.IsNullOrWhiteSpace(line.Substring(60, 9)) ? decimal.Parse(line.Substring(60, 9)) : new decimal(0);
                detalle.DetalleLineAD.PorcDscto = !string.IsNullOrWhiteSpace(line.Substring(69, 12)) ? decimal.Parse(line.Substring(69, 12)) : new decimal(0);
                detalle.DetalleLineAD.ValorDscto = !string.IsNullOrWhiteSpace(line.Substring(81, 16)) ? decimal.Parse(line.Substring(81, 16)) : new decimal(0);
                detalle.DetalleLineAD.ValorVentaNetoUnitario = !string.IsNullOrWhiteSpace(line.Substring(97, 15)) ? decimal.Parse(line.Substring(97, 15)) : new decimal(0);
                detalle.DetalleLineAD.ValorVentaTotal = !string.IsNullOrWhiteSpace(line.Substring(112, 15)) ? decimal.Parse(line.Substring(112, 15)) : new decimal(0);
                detalle.DetalleLineAD.Campo1 = line.Substring(127, 5);
            }
        }
    }
}
